<template>
    <div class="user-info">
        <el-tabs :tab-position="tabPosition">
            <el-tab-pane label="基础信息">
                <el-form ref="form" :model="form" label-width="100px">
                    <el-form-item label="用户名" prop="name">
                        <el-input v-model="form.name" placeholder="请输入昵称"></el-input>
                    </el-form-item>
                    <el-form-item label="手机号" prop="telephone">
                        <el-input v-model="form.telephone" placeholder="请输入手机号"></el-input>
                    </el-form-item>
                    <el-form-item label="邮箱" prop="">
                        <el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <div style="text-align: center;">
                            <el-button @click="resetForm('form')">取消</el-button>
                            <el-button type="primary" @click="submitForm('form')">保存</el-button>
                        </div>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
            <el-tab-pane label="安全设置">
                <el-form ref="form" :model="form" label-width="100px">
                    <el-form-item label="账户" prop="username">
                        {{ account }}
                    </el-form-item>
                    <el-form-item label="密码" prop="password">
                        <el-input  placeholder="请输入密码" v-model="form.password" show-password><i slot="prefix" style="font-size: x-large;color: #303133;" class="el-input__icon el-icon-lock"></i></el-input>

                        <!-- <el-input v-model="form.password" type="password" placeholder="请输入"></el-input> -->
                    </el-form-item>
                    <el-form-item>
                        <div style="text-align: center;">
                            <el-button @click="resetForm('form')">取消</el-button>
                            <el-button type="primary" @click="submitForm('form')">保存</el-button>
                        </div>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
        </el-tabs>
        <!-- <div style="text-align: center;">
            <el-button @click="resetForm('form')">取消</el-button>
            <el-button type="primary" @click="submitForm('form')">保存</el-button>
        </div> -->
    </div>  
</template>

<script>

    export default {
      name: 'userInfo',
      data() {
        return {
            tabPosition: '',
            account: '',
            username: '',
            isadmin: '',
            form: {
                id: '',
                name: '',
                telephone: '',
                password: '',
                email: ''
            }
        }
      },
      created(){
        let userinfo = JSON.parse(sessionStorage.getItem('userinfo'))
        this.account = userinfo.account
        this.form.name = userinfo.name
        this.form.password = userinfo.password
        this.form.telephone = userinfo.telephone
        this.form.email = userinfo.email
        this.form.id = userinfo.id
        this.isadmin = sessionStorage.getItem('isadmin')
      },
      mounted(){},
      methods: {
        submitForm(){
            this.$http.post(`/user/update`, this.form).then(res => {
                console.log(res , 'code');
                if (res.code == 200){
                    // this.$store.commit('setUser', {...res.data})
                    // this.$store.commit('setToken', res.data.token)
                    sessionStorage.setItem('userinfo', JSON.stringify(res.data))
                    // sessionStorage.setItem('account', res.data.account)
                    sessionStorage.setItem('userid', res.data.id)
                    // sessionStorage.setItem('username', res.data.name)
                    // sessionStorage.setItem('password', this.form.password)
                    sessionStorage.setItem('isadmin', res.data.isadmin)
                    sessionStorage.setItem("token", res.data.token);
                    // this.$router.push('/index')
                    this.$message.success('修改成功');
                } else {
                    this.$message.error(res.message)
                }
            }).catch((error) => {
                this.$message.error(error)
            })
        }
      }
  }
</script>
<style lang="scss" scoped>
.user-info{
    background-color: #fff;
    padding: 20px;
    height: 100%;
    .el-form{
        width: 500px;
    }
}

</style>